(function($) {

  var $loading_div = $("<div/>").text("loading...").addClass("myloading").css({
    "background-color" : "#2D2D2D",
    color : "white",
    position : "absolute",
    top : "2px",
    left : "2px",
    "border-radius" : "4px",
    padding: "0px 4px",
    "font-size": "12px",
  });

  $.fn.loading = function(open) {

    if (typeof open == "undefined")
      open = true;
    if (open) {
      return this.each(function() {
        var $loading = $(this).find(".myloading:first");
        if ($loading.size() > 0)
          $loading.show();
        else
          $(this).append($loading_div.clone());
      });
    } else {
      return this.each(function() {
        $(this).find(".myloading:first").hide();
      });
    }
  }
})(jQuery);